<?php echo $this-> tinyMce; ?>
<?php
	$options_jenis_test = array('' => "Select");
	foreach ($jenis_test as $row)
	{
        $options_jenis_test[$row['id']] = $row['name'];
	}
?>

<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h1><i class="glyphicon glyphicon-list-alt"></i> Soal <small>(Soal pada setiap jenis tes)</small></h1>
			<ol class="breadcrumb">
				<li><a href="<?php echo base_url(); ?>admin"><i class="glyphicon glyphicon-home"></i> Dashboard</a></li>
				<li class="active"><i class="glyphicon glyphicon-list-alt"></i> Soal</li>
			</ol>
			<?php
			if(isset($flash_message)){
				if($flash_message == TRUE)
				{
				  ?>
				  <div class="alert alert-info alert-dismissable">
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<strong>Well done!</strong> new user created with success.
				  </div>
				  <?php       
				}else{
				  ?>
				  <div class="alert alert-error alert-dismissable">
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<strong>Oh snap!</strong> change a few things up and try submitting again.
				  </div>
				  <?php
				}
			}
			?>
		</div>
	</div><!-- /.row -->
	
	<div class="row">
		<div class="col-lg-12">
			<h2>Daftar Soal <a  role="button" data-toggle="modal" data-target=".bs-baru-modal-lg" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-plus"></i> Add a new</a></h2>
			<div class="table-responsive">
			<table class="table table-bordered table-hover table-striped tablesorter">
				<thead>
                  <tr>
                    <th>No</th>
                    <th width="5%">id <i class="glyphicon glyphicon-sort"></i></th>
                    <th width="25%">Soal <i class="glyphicon glyphicon-sort"></i></th>
                    <th width="10%">Jenis Tes <i class="glyphicon glyphicon-sort"></i></th>
                    <th>Kunci</th>
                    <th width="255px">Actions</th>
                  </tr>
				</thead>
				<tbody>
                  <?php foreach($data as $row){ ?>
				  <tr>
                    <td><?php echo$no; ?></td>
                    <td><?php echo$row['id']; ?></td>
                    <td><?php echo$row['soal']; ?></td>
                    <td><?php echo$options_jenis_test[$row['jenis_test_id']]; ?></td>
                    <td>
					<?php
						$no_kunci = 1;
						foreach($kunci[$row['id']] as $id_kunci)
						{
							echo '<b>'.$no_kunci.'=></b> '.$id_kunci['kunci'].' ('.$id_kunci['skor'].')
							<a role="button" class="btn btn-info btn-xs" data-toggle="popover bottom" data-target=""><i class="glyphicon glyphicon-pencil"></i> Edit</a>
							<a href="'.site_url('admin').'/kunci/delete/'.$id_kunci['id'].'"role="button" class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"></i> Delete</a>
							<br><br>';
							$no_kunci++;
						}
					?>
					</td>
                    <td>
						<a role="button" data-toggle="modal" data-target=".bs-kunci<?php echo$row['id']; ?>-modal-lg" class="btn btn-warning btn-sm"><i class="glyphicon glyphicon-plus-sign"></i> Kunci Baru</a>  
						<a role="button" data-toggle="modal" data-target=".bs-edit<?php echo$row['id']; ?>-modal-lg" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-pencil"></i> Edit</a>  
						<a href="<?php echo site_url('admin'); ?>/soal/delete/<?php echo$row['id']; ?>" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-trash"></i> Delete</a>
					</td>
                  </tr>
				  <?php $no++; } ?>
				</tbody>
			</table>
			</div>
			
			<?php echo '<div class="pagination">'.$this->pagination->create_links().'</div>'; ?>
			
		</div>
	</div><!-- /.row -->
</div>

<div class="popover bottom">
      <div class="arrow"></div>
      <h3 class="popover-title">Popover bottom</h3>

      <div class="popover-content">
        <p>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
      </div>
</div>

<!--baru-->
<div class="modal fade bs-baru-modal-lg" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
	<form action="<?php echo base_url(); ?>admin/soal/simpan" method="post">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h3 class="modal-title" id="myModalLabel"><i class="glyphicon glyphicon-plus"></i> <b>Tambah Soal</b></h3>
      </div>
      <div class="modal-body">
		<div class="form-group">
			<label>Soal</label>
			<textarea style="width:865px; height:300px" class="form-control" name="soal"></textarea>
		</div>
		<div class="form-group">
			<label>Jenis Test</label>
			<?php
				echo form_dropdown('id_jenis_test', $options_jenis_test, set_value('jenis_test_id'), 'class="form-control" style="width:200px"');
			?>
		</div>
      </div>
      <div class="modal-footer">
        <button type="reset" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-floppy-remove"></i> Batal</button>
        <button type="submit" class="btn btn-warning" data-dismiss=".modal"><i class="glyphicon glyphicon-floppy-saved"></i> Simpan</button>
      </div>
    </form>
	</div>
  </div>
</div>

<?php 
$no = 0;
foreach($data as $row){ ?>
<!--edit-->
<div class="modal fade bs-edit<?php echo$row['id']; ?>-modal-lg" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
	<form action="<?php echo base_url(); ?>admin/soal/ubah" method="post">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h3 class="modal-title" id="myModalLabel"><i class="glyphicon glyphicon-pencil"></i> <b>Ubah Soal</b></h3>
      </div>
      <div class="modal-body">
		<div class="form-group">
			<label>Soal</label>
			<input name="id" type="hidden" value="<?php echo$row['id']; ?>">
			<textarea style="width:865px; height:300px" class="form-control" name="soal"><?php echo$row['soal']; ?></textarea>
		</div>
		<div class="form-group">
			<label>Jenis Test</label>
			<?php
				echo form_dropdown('id_jenis_test', $options_jenis_test, $data[$no]['jenis_test_id'], 'class="form-control" style="width:200px"');
			?>
		</div>
      </div>
      <div class="modal-footer">
        <button type="reset" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-floppy-remove"></i> Batal</button>
        <button type="submit" class="btn btn-warning" data-dismiss=".modal"><i class="glyphicon glyphicon-floppy-saved"></i> Simpan</button>
      </div>
    </form>
	</div>
  </div>
</div>
<?php
$no++;
 } ?>

<?php foreach($data as $row){ ?>
<!--kunci-->
<div class="modal fade bs-kunci<?php echo$row['id']; ?>-modal-lg" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
	<form action="<?php echo base_url(); ?>admin/soal/kunci" method="post">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h3 class="modal-title" id="myModalLabel"><i class="glyphicon glyphicon-plus-sign"></i> <b>Tambah Kunci</b></h3>
      </div>
      <div class="modal-body">
		<div class="form-group">
			<label>Jawaban untuk soal : <?php echo$row['soal']; ?></label>
			<input name="soal_id" type="hidden" value="<?php echo$row['id']; ?>">
			<textarea style="width:865px; height:300px" class="form-control" name="kunci"></textarea>
		</div>
		<div class="form-group">
			<label>Skor</label>
			<input name="skor" type="text" value="" class="form-control" style="width:150px"  placeholder="Enter Skor">
		</div>
      </div>
      <div class="modal-footer">
        <button type="reset" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-floppy-remove"> </i> Batal</button>
        <button type="submit" class="btn btn-warning" data-dismiss=".modal"><i class="glyphicon glyphicon-floppy-saved"></i> Simpan</button>
      </div>
    </form>
	</div>
  </div>
</div>
<?php } ?>